home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / DEMON / DEVELOPER / FREENET / WORKBONE.ARC / Linux / WBone2 / workbone2.c < prev    next >
C/C++ Source or Header  |  1995-05-29  |  7KB  |  313 lines

  1. /*   WorkBone CD Rom Player Software
  2.  
  3.      Copyright (C) 1993  Thomas McWilliams
  4.  
  5.      This program is free software; you can redistribute it and/or modify
  6.      it under the terms of the GNU General Public License as published by
  7.      the Free Software Foundation; either version 2, or (at your option)
  8.      any later version.
  9.  
  10.      This program is distributed in the hope that it will be useful,
  11.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.      GNU General Public License for more details.
  14.  
  15.      You should have received a copy of the GNU General Public License
  16.      along with this program; if not, write to the Free Software
  17.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. */
  20.  
  21. /*   Modified for use with the Acorn RISC-OS WorkBone client software.
  22.  *   An original version of WorkBone is supplied with the distribution
  23.  *   of this software.
  24.  *
  25.  *   No warranties etc. Tony Howat (thowat@xargle.demon.co.uk) 28/05/95
  26.  */
  27.  
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include <sys/types.h>
  31. #include <sys/time.h>
  32. #include <signal.h>
  33. #include <unistd.h>
  34. #include <termios.h>
  35. #include <mntent.h>
  36. #include <getopt.h>
  37. #include "struct.h"
  38. #include "workbone2.h"
  39.  
  40. void control_panel (void);
  41. void rl_ttyset (int Reset);
  42. void strmcpy (char **t, char *s);
  43. void help (void);
  44. inline void playtime (void);
  45.  
  46. char *cur_trackname;        /* Take a guess */
  47. int cur_index = 0;        /* Current index mark */
  48. int cur_frame;            /* Current frame number */
  49. struct play *playlist = NULL;
  50. struct cdinfo thiscd, *cd = &thiscd;
  51. int cur_track = -1;        /* Current track number, starting at 1 */
  52. char *cur_artist;        /* Name of current CD's artist */
  53. char cur_avoid;            /* Avoid flag */
  54. char cur_contd;            /* Continued flag */
  55. char *cur_cdname;        /* Album name */
  56. int cur_nsections;        /* Number of sections currently defined */
  57. int exit_on_eject = 0;
  58.  
  59. int cur_balance = 10, info_modified;
  60. int cur_track, cur_pos_abs, cur_pos_rel, cur_tracklen, cur_cdlen, cur_cdmode,
  61.   cur_ntracks, cur_lasttrack, cur_firsttrack, cur_listno;
  62. char tmptime[100];
  63. char *tottime;
  64.  
  65. int
  66. main (int argc, char *argv[])
  67. {
  68.  
  69.   int sss, sel_stat, dly;
  70.   int fastin = FALSE;
  71.   int scmd = 0, tmppos = 0;
  72.   int save_track = 1;
  73.   fd_set rset;
  74.   struct timeval mydelay;
  75.   struct mntent *mnt ;
  76.   char copt;
  77.   FILE *fp ;
  78.   thiscd.trk = NULL;
  79.   thiscd.lists = NULL;
  80.   mydelay.tv_sec = 0;
  81.   mydelay.tv_usec = 200000;
  82.   tottime = tmptime;
  83.  
  84.   /* get options */
  85.   for (;;)
  86.     {
  87.       if ((copt = getopt (argc, argv, "hqvV")) == EOF)
  88.     break;
  89.       switch (copt)
  90.     {
  91.     case 'q':
  92.       fastin = TRUE;
  93.       break;
  94.     default:
  95.       printf ("\nWorkBone version 0.1 Copyright 1993 (c) Thomas McWilliams\n");
  96.           printf ("This version modified by Tony Howat for use with the\n");
  97.           printf ("RISC-OS workbone client.\n");
  98.       printf ("Free Software under GNU General Public License.\n\n");
  99.       printf ("Useage:  workbone [ -v | -h | -q ]\n");
  100.       printf ("           -v : version\n");
  101.       printf ("           -h : help\n");
  102.       printf ("           -q : fast start (no wait for init)\n\n");
  103.       printf ("Type 'workbone' to start program.\n\n");
  104.       printf ("Engage the NUM LOCK on your keypad. From inside WorkBone\n");
  105.       printf ("pressing DEL on numeric keypad will display a help menu.\n\n");
  106.       exit (0);
  107.     }
  108.     }
  109.   /* check if drive is mounted (from Mark Buckaway's cdplayer code) */
  110.   if ((fp = setmntent (MOUNTED, "r")) == NULL)
  111.     {
  112.       fprintf (stderr, "Couldn't open %s: %s\n", MOUNTED, strerror (errno));
  113.       exit (1);
  114.     }
  115.   while ((mnt = getmntent (fp)) != NULL)
  116.     {
  117.       if (strcmp (mnt->mnt_type, "iso9660") == 0)
  118.     {
  119.       fputs ("CDROM already mounted. Operation aborted.\n", stderr);
  120.       endmntent (fp);
  121.       exit (1);
  122.     }
  123.     }
  124.   endmntent (fp);
  125.  
  126.   /* delay while CD drive initializes itself */
  127.   if (!fastin)
  128.     for (dly = 6; dly > -1; dly--)
  129.       {
  130.     printf ("wait ... initializing %d\r", dly);
  131.     fflush (stdout);
  132.     sleep (1);
  133.       }
  134.   printf ("                         \r");
  135.   fflush (stdout);
  136.   sss = cd_status ();
  137.   rl_ttyset (0);
  138.   if (sss == 0 || sss == 4)
  139.     goto done;
  140.   cur_track = 1;
  141.   printf ("ready\r");
  142.   fflush(stdout);
  143.  
  144.   do
  145.     {
  146. /*
  147. use select() to update status every 200 millisecs or
  148. sooner if keypad has data
  149. */
  150.  
  151.       FD_ZERO (&rset);
  152.       FD_SET (STDIN_FILENO, &rset);
  153.       sel_stat = select (4, &rset, NULL, NULL, &mydelay);
  154.       sss = cd_status ();
  155.       if (sss == 0 || sss == 4 || cur_cdmode == CDEJECT)
  156.     {
  157.       scmd = '0';
  158.       goto done;
  159.     }
  160.       if (cur_cdmode < 1)
  161.     save_track = 1;
  162.       /* if key was pressed, parse it and do function */
  163.       if (FD_ISSET (STDIN_FILENO, &rset))
  164.     {
  165.       read (0, &scmd, 1);
  166.       switch (scmd & 255)
  167.         {
  168.         case '.':
  169.         case '?':
  170.           help ();
  171.           break;
  172.         case '1':
  173.           if (cur_cdmode == CDPLAY)
  174.         {
  175.           tmppos = cur_pos_rel - 15;
  176.           play_cd (cur_track, tmppos > 0 ? tmppos : 0, cur_ntracks + 1);
  177.         }
  178.           break;
  179.         case '3':
  180.           if (cur_cdmode == CDPLAY)
  181.         {
  182.           tmppos = cur_pos_rel + 15;
  183.           if (tmppos < thiscd.trk[cur_track - 1].length)
  184.             play_cd (cur_track, tmppos, cur_ntracks + 1);
  185.         }
  186.           break;
  187.         case '2':
  188.           stop_cd ();
  189.           eject_cd ();
  190.           break;
  191.         case '4':
  192.           cur_track--;
  193.           if (cur_track < 1)
  194.         cur_track = cur_ntracks;
  195.           play_cd (cur_track, 0, cur_ntracks + 1);
  196.           break;
  197.         case '5':
  198.           if (cur_cdmode == CDPLAY)
  199.         play_cd (cur_track, 0, cur_ntracks + 1);
  200.           break;
  201.         case '6':
  202.           if (cur_track == cur_ntracks)
  203.         cur_track = 0;
  204.           play_cd (cur_track + 1, 0, cur_ntracks + 1);
  205.           break;
  206.         case '7':
  207.           save_track = cur_track;
  208.           stop_cd ();
  209.           break;
  210.         case '8':
  211.           if (cur_cdmode == CDPLAY || cur_cdmode == CDPAUZ)
  212.         {
  213.           pause_cd ();
  214.         }
  215.           break;
  216.         case '9':
  217.           if (cur_cdmode == CDSTOP || cur_cdmode == CDNULL)
  218.         {
  219.           play_cd (save_track, 0, cur_ntracks + 1);
  220.         }
  221.           break;
  222.         default:
  223.           break;
  224.         }
  225.     }
  226.       /* update display of which track is playing */
  227.       switch (cur_cdmode)
  228.     {
  229.     case 0:        /* CDNULL */
  230.       cur_track = save_track = 1;
  231.       printf ("stp\r");
  232.       break;
  233.     case 1:        /* CDPLAY */
  234.       playtime ();
  235.       printf ("ply,%d,%s\r", cur_track, tottime);
  236.       break;
  237.     case 3:        /* CDPAUZ */
  238.       printf ("pse,%d  \r", cur_track);
  239.       break;
  240.     case 4:        /* CDSTOP */
  241.       printf ("stp,%d \r", save_track);
  242.       break;
  243.     case 5:        /* CDEJECT */
  244.       goto done;
  245.     default:
  246.       printf ("cur_cdmode %d       \r", cur_cdmode);
  247.     }
  248.       fflush (stdout);
  249.  
  250.     }
  251.   while (scmd != '0');
  252. done:
  253.   if (thiscd.trk != NULL)
  254.     free (thiscd.trk);
  255.   printf ("close\r");
  256.   printf ("\n");
  257.   rl_ttyset (1);
  258.   return(0);
  259. }
  260.  
  261. /* takes terminal in and out of raw mode */
  262. void
  263. rl_ttyset (int Reset)
  264. {
  265. }
  266.  
  267.  
  268. /* Copy into a malloced string. */
  269. void
  270. strmcpy (char **t, char *s)
  271. {
  272.   if (*t != NULL)
  273.     free (*t);
  274.  
  275.   *t = malloc (strlen (s) + 1);
  276.   if (*t == NULL)
  277.     {
  278.       perror ("strmcpy");
  279.       exit (1);
  280.     }
  281.  
  282.   (void) strcpy (*t, s);
  283. }
  284.  
  285. /* ansi codes to clear screen */
  286. void
  287. cls ()
  288. {
  289. }
  290.  
  291. /* print help screen */
  292. void
  293. help ()
  294. {
  295. }
  296.  
  297. inline void
  298. playtime (void)
  299. {
  300.   static int mymin, emin;
  301.   static int mysec, esec;
  302.   int tmp = 0;
  303.  
  304.   if (cur_pos_rel > 0 && (tmp = cur_pos_rel % 60) == mysec)
  305.     return;
  306.   mysec = tmp;
  307.   mymin = cur_pos_rel / 60;
  308.   esec = cur_pos_abs % 60;
  309.   emin = cur_pos_abs / 60;
  310.   sprintf (tmptime, "%02d,%02d",mymin, mysec);
  311.   return;
  312. }
  313.